﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using BusinnessLogic;
using DataLayer;
using Model;

namespace scrumbench
{
    public partial class NewTask : Form
    {
        public NewTask()
        {
            InitializeComponent();
        }

        public NewTask(int userstory, int team, string userstoryname)
        {
            InitializeComponent();
            teamid = team;
            userstoryId = userstory;
            this.userstoryname = userstoryname;
        }

        private string userstoryname;

        public string Userstoryname
        {
            get { return userstoryname; }
            set { userstoryname = value; }
        }

        private int userstoryId;

        public int UserstoryId
        {
            get { return userstoryId; }
            set { userstoryId = value; }
        }

        private string titel;

        public string Titel
        {
            get { return titel; }
            set { titel = value; }
        }

        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        private int estimatedWorkload;

        public int EstimatedWorkload
        {
            get { return estimatedWorkload; }
            set { estimatedWorkload = value; }
        }

        private int userid;

        public int Userid
        {
            get { return userid; }
            set { userid = value; }
        }

        private int teamid;

        public int Teamid
        {
            get { return teamid; }
            set { teamid = value; }
        }

        private void NewTask_Load(object sender, EventArgs e)
        {
            this.Text = "Add a new Task to UserStory: " + userstoryname;
            
            ManageUsers mijnuserlist = new ManageUsers();
            List<User> allusers = new List<User>();
            allusers = mijnuserlist.PopulateUserlist();

            foreach (User mijnuser in allusers)
            {
                if (mijnuser.TeamID == teamid)
                {
                    comboBox1.Items.Add(mijnuser);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            titel = textBox1.Text;
            description = textBox2.Text;
            estimatedWorkload = Convert.ToInt32(textBox3.Text);

            InsertProduct iprod = new InsertProduct();
            iprod.Inserttask(titel, description, estimatedWorkload, userid, userstoryId);
        }

        private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            string user = comboBox1.SelectedItem.ToString();

            ManageUsers mijnuserlist = new ManageUsers();
            List<User> allusers = new List<User>();
            allusers = mijnuserlist.PopulateUserlist();

            foreach (User mijnuser in allusers)
            {
                if (user == mijnuser.name)
                {
                    userid = mijnuser.UserID;
                    break;
                }
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}
